package com.mm.cloud.common.security.config;

import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 参数校验配置
 *
 * @author mr
 * @since 2021-06-09
 */
@Configuration
public class ValidatorConfiguration {

    @Bean
    public Validator validator() {
        ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class)
                .configure()
                .addProperty("hibernate.validator.fail_fast", "false")//快速返回模式，校验到第一个参数错误时，即可返回错误，默认为普通返回模式
                .buildValidatorFactory();
        return validatorFactory.getValidator();
    }
}
